package com.mdx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mdx.bean.ExpertBean;
import com.mdx.service.IExpertService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 专家
 */
@RestController
@RequestMapping("expert")
public class ExpertController {
    @Resource
    private IExpertService expertService;

    //查询所有专家
    @RequestMapping("findAll")
    public IPage<ExpertBean> findAll(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                     @RequestParam(value = "pageSize", defaultValue = "2") int pageSize){
        return expertService.findByItem(pageNO,pageSize,null,null,null);
    }

    //修改专家信息
    @RequestMapping("update")
    public String update(int expertId,String expertTel,String office,String jobUnit,String email){
        expertService.updateById(expertId,expertTel,office,jobUnit,email);
        return "ok";
    }

    //添加
    @RequestMapping("add")
    public String add(ExpertBean expertBean){
        expertService.save(expertBean);
        return "ok";
    }

    //根据id查询专家详情
    @RequestMapping("findById")
    public ExpertBean findById(int expertId){
        return expertService.getById(expertId);
    }

    @RequestMapping("del")
    public String delById(int expertId){
        expertService.removeById(expertId);
        return "ok";
    }

    //模糊查询
    @RequestMapping("findByItem")
    public IPage<ExpertBean> findByItem(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                       @RequestParam(value = "pageSize", defaultValue = "2") int pageSize,
                                        String expertName,String specialty,String jobUnit){
        return expertService.findByItem(pageNO,pageSize,expertName,specialty,jobUnit);
    }
}
